#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int minimumRecolors(string blocks, int k) {
        int cntW = 0;  // 窗口中白色的数量
        for (int i = 0; i < k; ++i) {
            cntW += blocks[i] & 1;
        }
        int res = cntW;
        for (int i = k; i < blocks.size(); ++i) {
            cntW += (blocks[i] & 1) - (blocks[i - k] & 1);
            res = min(res, cntW);
        }
        return res;
    }
};

int main() {
    Solution s;

    string blocks1 = "WBBWWBBWBW";
    string blocks2 = "WBWBBBW";

    int k1 = 7;
    int k2 = 2;

    int res1 = 3;
    int res2 = 0;

    assert(s.minimumRecolors(blocks1, k1) == res1);
    assert(s.minimumRecolors(blocks2, k2) == res2);

    dbg('W' & 1);
    dbg('B' & 1);

    return 0;
}